package ooday04_practice;

public class PolymorphicDemo {

    public static void main(String[] args) {

        Master master = new Master();

        Dog[] dogs = new Dog[2];
        dogs[0] = new Dog("Alice", 1, "blue");
        dogs[1] = new Dog("Bob", 2, "red");

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("Cc",3,"green");
        chicks[1] = new Chick("Diver", 4, "black");

        Fish[] fish = new Fish[2];
        fish[0] = new Fish("Free", 5,"yellow");
        fish[1] = new Fish("Grow", 6, "purple");

        Animal[] animals = new Animal[6];
        animals[0] = dogs[0];
        animals[1] = dogs[1];
        animals[2] = chicks[0];
        animals[3] = chicks[1];
        animals[4] = fish[0];
        animals[5] = fish[1];

        for (int i = 0; i < 6; i++){

            animals[i].eat();
            animals[i].drink();

            master.feed(animals[i]);
            master.feedWater(animals[i]);

            if (animals[i] instanceof Dog){
                Dog dog = (Dog) animals[i];
                dog.lookHome();
            }

            if (animals[i] instanceof Chick){
                Chick chick = (Chick) animals[i];
                chick.layEgg();
            }

            if (animals[i] instanceof Swim){
                Swim swim = (Swim) animals[i];
                swim.swim();
            }

        }

        Animal animal = new Animal(){
          public void eat(){
              System.out.println("匿名内部类！");
          }
        };
        animal.eat();

    }

}
